package futian
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.events.Event;
	public class FirstPage extends Sprite
	{
		private static var _main:FirstPage = null;
		public static function get main():FirstPage
		{
			if(_main==null)
				_main = new FirstPage();
			return _main;
		}
		private var bg:Bitmap;
		public function FirstPage()
		{
			_main = this;
			bg = new Bitmap(test.main.bg.bitmapData);
			addChild(bg);
			photoBtn = new BtnBase(toPhoto,test.newBtn("点击拍照"));
			//photoBtn = new BtnBase(toPhoto,new Assets.b10_png);
			searchBtn = new BtnBase(toSign,test.newBtn("照片浏览"));
			//searchBtn = new BtnBase(toSign,new Assets.b20_png);
			sayBtn = new BtnBase(toSay,test.newBtn("留言箱"));
			//sayBtn = new BtnBase(toSay,new Assets.b30_png);
			phoneBtn = new BtnBase(toSay,test.newBtn("手机上传照片"));
			//315x108

			addChild(photoBtn);
			addChild(phoneBtn);
			addChild(searchBtn);
			addChild(sayBtn);
			phoneBtn.x = photoBtn.x = searchBtn.x = sayBtn.x = 1416;
			photoBtn.y = 243;
			phoneBtn.y = 396;
			searchBtn.y = 534;
			sayBtn.y = 680;

			//[Embed(source="btn/back.png")] var backpng:Class; addChild(new backpng);

			width = test.stageW;
			height = test.stageH;

			//SwfLoader.SwfLoad("1.png",loaded);
		}

		private function loaded(e:Event):void
		{
			if(e && e.type==Event.COMPLETE)
			{
				if(bg)
				{
					if(contains(bg))
						removeChild(bg);
				}
				bg = e.target.content as Bitmap;
				if(bg)
				{
					addChildAt(bg,0);
					CONFIG::debugging{
						return;
					}
					phoneBtn.alpha = photoBtn.alpha = searchBtn.alpha = sayBtn.alpha = 0;
				}
			}
		}


		private var photoBtn:BtnBase;
		private var searchBtn:BtnBase;
		private var phoneBtn:BtnBase;
		private var sayBtn:BtnBase;

		private function toPhoto():void
		{
			logs.adds("拍照");
			CameraPage.show();
			visible = false;
		}
		private function toSign():void
		{
			logs.adds("签名统计");
			//StatisticsPage.show();
			visible = false;
		}
		private function toSay():void
		{
			logs.adds("留言");
			SayPage.show();
			visible = false;
		}

		private static var indexTxt:TextField;
		public static var photoPlayer:PhotoPlayer;
		private static const hasPhotoPlayer:Boolean = true;
		public static function show():void
		{
			main.visible = true;
			test.main.addChild(main);
			indexTxt = Datas.setIndexTxt(indexTxt);
			main.addChild(indexTxt);


			if(hasPhotoPlayer)
			{
				if(photoPlayer==null)
				{
					photoPlayer = new PhotoPlayer(1920,1080);
				}
				main.addChild(photoPlayer);
			}else{
				if(photoPlayer)
					photoPlayer.stop();
			}
		}
		public static function back():void
		{
			main.visible = false;
			//FirstPage.show();
		}
	}
}
